<template>
  <div v-if="pageflag" class="left_boottom_wrap beautify-scroll-def" :class="{ 'overflow-y-auto': !sbtxSwiperFlag }">
    <template v-if="list.length > 0">
      <vueSeamlessScroll :data="list" :class-option="defaultOption" @mouseover="handleMouseOver" @mouseout="handleMouseOut" ref="seamlessScroll">
        <ul class="left_boottom">
          <li class="left_boottom_item" v-for="(item,i) in list" :key="i">
            <span class="orderNum doudong">{{ i + 1 }}</span>
            <div class="inner_right">
              <div class="dibu"></div>
              <div class="flex">
                <div class="info">
                  <span class="labels">{{ $t('bigScreen.poleNo') }}：</span>
                  <span class="contents zhuyao doudong wangguan">{{ item.boxNo }}</span>
                </div>
                <div class="info">
                  <span class="labels">{{ $t('bigScreen.time') }}：</span>
                  <span class="contents " style="font-size: 13px">{{ item.createTime }}</span>
                </div>
              </div>
              <span class="types doudong" :class="{ typeRed: item.state === '0', typeGreen: item.state === '1'}">
                {{ item.state === '1' ? $t('bigScreen.online') : $t('bigScreen.offline') }}
              </span>
              <div class="info addresswrap">
                <span class="labels">{{ $t('bigScreen.address') }}：</span>
                <span class="contents ciyao" style="font-size: 12px">{{ item.city }}</span>
              </div>
            </div>
          </li>
        </ul>
      </vueSeamlessScroll>
    </template>
    <template v-else>
      <div class="no-data">{{ $t('bigScreen.noData') }}</div>
    </template>
  </div>
  <Reacquire v-else @onclick="getData" style="line-height: 200px" />
</template>
<script>
import vueSeamlessScroll from "vue-seamless-scroll"; // vue2引入方式
import Kong from "../components/kong.vue";
import {listHgbox1 } from '@/api/iot/hgbox'
export default {
  components: { vueSeamlessScroll, Kong },
  data() {
    return {
      list: [],
      pageflag: true,
      components: vueSeamlessScroll,
      defaultOption: {
        ...this.$store.state.settings.defaultOption,
        singleHeight: 240,
        limitMoveNum: 5,
        step: 0,
      },
    };
  },
  computed: {
    sbtxSwiperFlag() {
      let sbtxSwiper = this.$store.state.settings.sbtxSwiper;
      if (sbtxSwiper) {
        this.components = vueSeamlessScroll;
      } else {
        this.components = Kong;
      }
      return sbtxSwiper;
    },
  },
  created() {
    this.getData();
  },
  mounted() {
    this.checkScrollEnd();
  },
  methods: {
    handleMouseOver() {
      this.defaultOption.step = 0;
    },
    handleMouseOut() {
      this.defaultOption.step = this.$store.state.settings.defaultOption.step;
    },
    checkScrollEnd() {
      const scrollElement = this.$refs.seamlessScroll.$el;
      scrollElement.addEventListener('scroll', () => {
        if (scrollElement.scrollHeight - scrollElement.scrollTop === scrollElement.clientHeight) {
          // 滚动到底部时停止滚动
          this.defaultOption.step = 0;
        } else {
          // 滚动未到底部时恢复滚动
          this.defaultOption.step = this.$store.state.settings.defaultOption.step;
        }
      });
    },
    getData() {
      this.pageflag = true;
      listHgbox1().then((res) => {
        if (res.code === 200) {
          this.list = res.rows || []; // 确保list是数组
          console.log("200:"+this.list)
          let timer = setTimeout(() => {
            clearTimeout(timer);
            this.defaultOption.step = this.$store.state.settings.defaultOption.step;
          }, this.$store.state.settings.defaultOption.waitTime);
        } else {
          this.pageflag = false;
          this.list = []; // 确保出错时list为空数组
          this.$Message.warning(res.msg);
        }
      }).catch(() => {
        this.list = []; // 捕获异常时也清空list
      });
    },
  },
};
</script>
<style lang='scss' scoped>
.no-data {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  color: rgba(239, 255, 0, 1.0);
  font-size: 14px;
}
.left_boottom_wrap {
  overflow: scroll;
  width: 100%;
  height: 100%;
}
.doudong {
  //  vertical-align:middle;
  overflow: hidden;
  -webkit-backface-visibility: hidden;
  -moz-backface-visibility: hidden;
  -ms-backface-visibility: hidden;
  backface-visibility: hidden;
}
.overflow-y-auto {
  overflow-y: auto;
}
.left_boottom {
  width: 100%;
  height: 100%;
  .left_boottom_item {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    font-size: 14px;
    margin: 10px 0;
    .orderNum {
      margin: 0 16px 0 -20px;
    }
    .info {
      margin-right: 10px;
      display: flex;
      align-items: center;
      color: #fff;
      .labels {
        flex-shrink: 0;
        font-size: 12px;
        color: rgba(255, 255, 255, 0.6);
      }
      .zhuyao {
        // color: $primary-color;
        font-size: 15px;
      }
      .ciyao {
        color: rgba(255, 255, 255, 0.8);
      }
      .warning {
        color: #e6a23c;
        font-size: 15px;
      }
    }
    .inner_right {
      position: relative;
      height: 100%;
      width: 380px;
      flex-shrink: 0;
      line-height: 1;
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-wrap: wrap;
      .dibu {
        position: absolute;
        height: 2px;
        width: 104%;
        background-image: url("../../../assets/bigScreen/img/zuo_xuxian.png");
        bottom: -10px;
        left: -2%;
        background-size: cover;
      }
      .addresswrap {
        width: 100%;
        display: flex;
        margin-top: 8px;
      }
    }
    .wangguan {
      color: #1890ff;
      font-weight: 900;
      font-size: 15px;
      width: 80px;
      flex-shrink: 0;
    }
    .time {
      font-size: 12px;
      // color: rgba(211, 210, 210,.8);
      color: #fff;
    }
    .address {
      font-size: 12px;
      cursor: pointer;
      // @include text-overflow(1);
    }
    .types {
      width: 30px;
      flex-shrink: 0;
    }
    .typeRed {
      color: rgba(252, 26, 26, 0.87);
    }
    .typeGreen {
      color: #29fc29;
    }
  }
}
</style>
